home *** CD-ROM | disk | FTP | other *** search
- unit uCalling;
-
- {
- *******************************************************************************
- * Descriptions: Calling/Called Popup Implementation
- * $Source: /cvsroot/fma/fma/uCalling.pas,v $
- * $Locker: $
- *
- * Todo:
- * - Update to support note taking for the active caller
- *
- * Change Log:
- * $Log: uCalling.pas,v $
- * Revision 1.14.6.1 2005/01/25 16:03:07 z_stoichev
- * Merged with 2.1 Beta 1 bugfixes
- *
- * Revision 1.14 2004/07/07 09:41:41 z_stoichev
- * Common image usage
- * bugfixes.
- *
- * Revision 1.13 2004/07/06 14:06:52 z_stoichev
- * - Added Personalization default contact image.
- *
- * Revision 1.12 2004/06/29 15:23:54 z_stoichev
- * Add Call support without popups.
- *
- * Revision 1.11 2004/06/29 10:46:54 z_stoichev
- * Updated personalization
- * Added Call notes support
- *
- * Revision 1.10 2004/06/28 23:02:21 z_stoichev
- * Personalization and GUI changed.
- *
- * Revision 1.9 2004/06/15 15:30:30 z_stoichev
- * - Added Default Ringing sound support.
- * - Added Default Busy sound support.
- * - Added Handle RING signals (default sound).
- * - Added Second Incoming call is ignored.
- * - Added Cancel Incoming call silently support.
- * - Added Cancel Outgoing call warning message.
- *
- * Revision 1.8 2004/06/08 19:19:25 lordlarry
- * Memory Leak fixed
- *
- * Revision 1.7 2003/12/11 14:08:02 z_stoichev
- * Fixed Command return error on answer.
- * Timer and sound start adjusted to match phone ones.
- * Handle some possible exceptions.
- *
- * Revision 1.6 2003/11/28 09:38:07 z_stoichev
- * Merged with branch-release-1-1 (Fma 0.10.28c)
- *
- * Revision 1.5.2.8 2003/11/21 13:34:11 z_stoichev
- * Fixed headset button mark call as missed issue.
- *
- * Revision 1.5.2.7 2003/11/14 15:41:02 z_stoichev
- * Updates for patch 27d.
- *
- * Revision 1.5.2.6 2003/11/13 16:35:39 z_stoichev
- * Fixed personalization support.
- *
- * Revision 1.5.2.5 2003/11/12 16:48:52 z_stoichev
- * Do not show error on missing sound file.
- *
- * Revision 1.5.2.4 2003/11/12 15:19:03 z_stoichev
- * Temporary disconnect phone (during call) support.
- * Image auto-scale to fit.
- *
- * Revision 1.5.2.3 2003/11/11 18:11:06 z_stoichev
- * Add background image.
- * Show contact picture and play sound
- * if personalized in phonebook.
- *
- * Revision 1.5.2.2 2003/10/31 14:51:15 z_stoichev
- * Added headset button (disconnect on answer).
- *
- * Revision 1.5.2.1 2003/10/27 07:22:54 z_stoichev
- * Build 0.1.0 RC1 Initial Checkin.
- *
- * Revision 1.5 2003/10/15 15:49:55 z_stoichev
- * MIssed Calls Unicode support.
- * GUI changes.
- *
- * Revision 1.4 2003/02/17 06:51:16 crino77
- * Added support for missed calls
- *
- * Revision 1.3 2003/01/30 04:15:57 warren00
- * Updated with header comments
- *
- *
- *******************************************************************************
- }
-
- interface
-
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, Placemnt, TntStdCtrls, GR32_Image, ExtCtrls, MPlayer,
- jpeg, MMSystem, uSyncPhonebook;
-
- type
- TfrmCalling = class(TForm)
- HandupButton: TButton;
- AnswerButton: TButton;
- FormPlacement1: TFormPlacement;
- lbAlpha: TTntLabel;
- lbNumber: TTntLabel;
- HeadsetButton: TButton;
- ImagePanel: TPanel;
- Image32: TImage32;
- MediaPlayer1: TMediaPlayer;
- Image1: TImage;
- lblTime: TLabel;
- TimeTimer: TTimer;
- Memo: TTntMemo;
- procedure CallButtonClick(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure MediaPlayer1Notify(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure FormCreate(Sender: TObject);
- procedure TimeTimerTimer(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- private
- { Private declarations }
- FContact: PContactData;
- FStartTime: TDateTime;
- FPersonalized,FStopped: boolean;
- FIsIncoming: Boolean;
- FRingSecs,FRingOn: integer;
- FCheck,FCalling: Boolean;
- FCustomImage: Boolean;
- procedure Set_IsIncoming(const Value: Boolean);
- function Get_Busy: Boolean;
- procedure Set_Busy(const Value: Boolean);
- procedure Set_CustomImage(const Value: Boolean);
- public
- { Public declarations }
- procedure CreateCall(Number: WideString; Popup: boolean; AlphaBlend: Integer);
- procedure DoPersonalize;
- procedure DoResizeWide;
- procedure StopPersonalize(HidePic: boolean = True);
- function HasPersonalizedSound: boolean;
- published
- property IsIncoming: Boolean read FIsIncoming write Set_IsIncoming;
- property IsTalking: Boolean read FCheck write FCheck; { means: Are we picked up the call }
- property IsCalling: Boolean read FCalling write FCalling; { means: Should we hang up or not on exit? }
- property IsPersonalized: Boolean read FPersonalized; { means: Do we have personalized contact? }
- property IsCustomImage: Boolean read FCustomImage write Set_CustomImage;
- property IsBusy: Boolean read Get_Busy write Set_Busy; { means: Is busy signal detected? }
- end;
-
- var
- frmCalling: TfrmCalling;
-
- implementation
-
- uses Unit1, uMissedCalls;
-
- const
- DefRingOutgoingSecs = 5;
-
- {$R *.dfm}
-
- procedure TfrmCalling.CallButtonClick(Sender: TObject);
- begin
- if Sender = HandupButton then begin
- StopPersonalize;
- try
- Form1.VoiceHangUp;
- except
- end;
- end
- else
- if Sender = AnswerButton then begin
- StopPersonalize(False);
- try
- Form1.VoiceAnswer;
- except // Error may occur if call is alerady active...
- end;
- FCheck := True;
- if Visible and Memo.Visible then
- Memo.SetFocus;
- end
- else
- if Sender = HeadsetButton then begin
- StopPersonalize(False);
- try
- Form1.VoiceAnswer;
- except
- end;
- FCheck := True;
- Form1.DoDisconnectTemporary;
- end;
- (Sender As TButton).Enabled := False;
- end;
-
- procedure TfrmCalling.FormShow(Sender: TObject);
- begin
- SetWindowPos(Handle, HWND_TOPMOST,
- Top, Left, Width, Height,
- SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
- { temporary disable this feature
- HeadsetButton.Visible := False;
- {}
- end;
-
- procedure TfrmCalling.DoPersonalize;
- var
- s: string;
- w: WideString;
- begin
- { Try to lookup caller and load personalized info about the contact }
- if not FPersonalized then begin
- { Lookup contact name }
- if (lbAlpha.Caption = sUnknownNumber) or (lbAlpha.Caption = sUnknownContact) then
- lbAlpha.Caption := form1.LookupContact(lbNumber.Caption,lbAlpha.Caption);
- { Resize window if needed }
- DoResizeWide;
- { Personalize }
- w := Form1.ExtractContact(lbAlpha.Caption);
- if form1.frmSyncPhonebook.FindContact(w,FContact) then begin
- FPersonalized := True;
- if IsIncoming then
- Form1.ShowBaloonInfo(GetContactFullName(FContact)+' is calling...',60);
- // notes
- if not GetContactNotes(FContact,Memo.Lines) then
- Memo.Clear;
- Memo.Visible := True;
- // image
- try
- IsCustomImage := False;
- ImagePanel.Caption := 'Loading...';
- ImagePanel.Update;
- s := GetContactPictureFile(FContact);
- if s <> '' then begin
- Image32.Bitmap.LoadFromFile(s);
- IsCustomImage := True;
- end;
- Abort; // restore ImagePanel.Caption anyway!
- except
- ImagePanel.Caption := '<no photo>';
- end;
- // sound
- // WaitASec(500); // delay to sync our with phone sounds :)
- try
- s := GetContactSoundFile(FContact);
- if IsIncoming and (s <> '') then begin
- { Stop default ringing sound }
- if IsIncoming then PlaySound(nil, 0, SND_PURGE);
- { Play personalized sound }
- MediaPlayer1.FileName := s;
- MediaPlayer1.Open;
- MediaPlayer1.Play;
- MediaPlayer1.Notify := True;
- end
- else
- MediaPlayer1.FileName := '';
- except
- MediaPlayer1.FileName := '';
- end;
- FStopped := False;
- end
- else begin
- ImagePanel.Caption := '<no photo>';
- Memo.Lines.Clear;
- end;
- end;
- { Hide image and shift the rest to left if not personalized, and center contact name
- if not FPersonalized then begin
- // TODO
- end;
- { Play default ringing sound if no personalization set up for that contact,
- or if personalization is set up, but only for the contact picture, i.e. no sound }
- if (not FPersonalized or (MediaPlayer1.FileName = '')) then
- if IsIncoming then
- FStopped := not PlaySound(pChar('FMA_CallReceived'), 0, SND_ASYNC or SND_APPLICATION or SND_NODEFAULT)
- else
- FStopped := not PlaySound(pChar('FMA_Calling'), 0, SND_ASYNC or SND_APPLICATION or SND_NODEFAULT);
- end;
-
- procedure TfrmCalling.MediaPlayer1Notify(Sender: TObject);
- begin
- { loop sound }
- if FPersonalized and not FStopped and (MediaPlayer1.Mode = mpStopped) then
- try
- MediaPlayer1.Play;
- MediaPlayer1.Notify := True;
- except
- end;
- end;
-
- procedure TfrmCalling.StopPersonalize(HidePic: boolean);
- begin
- if not FStopped then begin
- FStopped := True;
- if HidePic then begin
- { Save contact notes }
- if IsCustomImage and FPersonalized and Assigned(FContact) then
- SetContactNotes(FContact,Memo.Lines);
- IsCustomImage := False;
- end
- else begin
- TimeTimer.Enabled := True;
- FStartTime := Now;
- end;
- if MediaPlayer1.FileName <> '' then
- try
- MediaPlayer1.Notify := False;
- if IsIncoming then
- try
- MediaPlayer1.Stop;
- MediaPlayer1.Close;
- except
- end;
- MediaPlayer1.FileName := '';
- except
- end
- else
- { Stop default ringing sound }
- PlaySound(nil, 0, SND_PURGE);
- Form1.CoolTrayIcon1.HideBalloonHint;
- end;
- end;
-
- procedure TfrmCalling.FormCloseQuery(Sender: TObject;
- var CanClose: Boolean);
- begin
- if IsCalling and not IsTalking and not IsIncoming then
- CanClose := MessageDlg('Closing this box will Hang Up current outgoing call. Continue?',
- mtConfirmation,[mbOk,mbCancel],0) = mrOk;
- end;
-
- procedure TfrmCalling.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- { Cancel any call attempt. If we're in call do not hang up here! }
- if IsCalling and not IsTalking then
- Form1.VoiceHangUp(IsIncoming);
- { Stop any sound }
- StopPersonalize;
- TimeTimer.Enabled := False;
- Image32.Bitmap.Clear;
- end;
-
- procedure TfrmCalling.FormCreate(Sender: TObject);
- begin
- lbAlpha.Font.Style := lbAlpha.Font.Style + [fsBold];
- Image1.Picture.Assign(Form1.CommonBitmaps.Bitmap[1]);
- end;
-
- procedure TfrmCalling.TimeTimerTimer(Sender: TObject);
- begin
- { This timer will be triggered once a call is active
- or when an outgoing call is sarted }
- if IsTalking then
- lblTime.Caption := FormatDateTime('nn:ss',Now - FStartTime)
- else
- if not IsIncoming then begin
- { perform default outgoing ringing sound on every RingSecs seconds }
- inc(FRingSecs);
- if FRingSecs = FRingOn then begin
- DoPersonalize;
- FRingSecs := 0;
- end;
- end;
- end;
-
- procedure TfrmCalling.Set_IsIncoming(const Value: Boolean);
- begin
- FIsIncoming := Value;
- if Visible then
- if Value then Form1.ShowBaloonInfo('Incoming call...',60);
- end;
-
- function TfrmCalling.HasPersonalizedSound: boolean;
- begin
- Result := FPersonalized and (MediaPlayer1.FileName <> '');
- end;
-
- function TfrmCalling.Get_Busy: Boolean;
- begin
- Result := FRingOn = 1;
- end;
-
- procedure TfrmCalling.Set_Busy(const Value: Boolean);
- begin
- if Value then FRingOn := 1 else FRingOn := DefRingOutgoingSecs;
- FRingSecs := 0;
- end;
-
- procedure TfrmCalling.CreateCall(Number: WideString; Popup: boolean; AlphaBlend: Integer);
- var
- CallName: WideString;
- begin
- { Setup variables }
- FRingSecs := 0;
- FRingOn := DefRingOutgoingSecs;
- FStopped := False;
- FPersonalized := False;
- FCheck := False;
- lblTime.Caption := '00:00';
- FContact := nil;
- Memo.Visible := False;
- HeadsetButton.Enabled := True;
- HeadsetButton.Visible := False;
- AnswerButton.Enabled := True;
- AnswerButton.Visible := False;
- HandupButton.Enabled := True;
- { Prepare transparancy }
- AlphaBlendValue := AlphaBlend;
- { Resize form to fix message }
- if Number = '' then CallName := sUnknownNumber
- else CallName := form1.LookupContact(Number,sUnknownContact);
- lbAlpha.Alignment := taLeftJustify;
- lbAlpha.AutoSize := True;
- lbAlpha.Caption := CallName;
- lbNumber.Caption := Number;
- IsCustomImage := False;
- { Restore form position }
- FormPlacement1.RestoreFormPlacement;
- Application.ProcessMessages;
- { Resize form }
- DoResizeWide;
- Height := Constraints.MinHeight;
- { Show window but not activate it
- ShowWindow(Handle,SW_SHOWNOACTIVATE);
- ShowWindow(HeadsetButton.Handle,SW_SHOWNOACTIVATE);
- ShowWindow(AnswerButton.Handle,SW_SHOWNOACTIVATE);
- ShowWindow(HandupButton.Handle,SW_SHOWNOACTIVATE);
- ShowWindow(Memo.Handle,SW_SHOWNOACTIVATE);
- ShowWindow(ImagePanel.Handle,SW_SHOWNOACTIVATE);
- ShowWindow(Image32.Handle,SW_SHOWNOACTIVATE);
- {}
- if Popup then
- Show;
- end;
-
- procedure TfrmCalling.DoResizeWide;
- var
- wide: integer;
- begin
- wide := lbAlpha.Width;
- if lbNumber.Width > wide then wide := lbNumber.Width;
- wide := wide + lbAlpha.Left - 4;
- if wide > (Constraints.MinWidth-16) then
- ClientWidth := wide + 8
- else
- Width := Constraints.MinWidth;
- end;
-
- procedure TfrmCalling.Set_CustomImage(const Value: Boolean);
- begin
- FCustomImage := Value;
- if not Value then
- Image32.Bitmap.Assign(Form1.CommonBitmaps.Bitmap[0]);
- end;
-
- end.
-